/* 1189. “气球” 的最大数量 */
/**
 * @param {string} text
 * @return {number}
 */
/* 哈希表 */
var maxNumberOfBalloons = function (text) {
    let res = 0
    if (text.length === 1) return res
    const str = "balloon"
    const map = new Map()
    for (const value of text) {
        if (str.includes(value)) {
            map.set(value, map.get(value) ? map.get(value) + 1 : 1)
        }
    }
    while (map.get('b')) {
        let index = 0
        for (let i = 0; i < str.length; i++) {

            if (map.has(str[i]) && map.get(str[i]) > 0) {
                index++
                map.set(str[i], map.get(str[i]) - 1)
            }
            if (index === str.length) {
                res++
                index = 0
            }
        }
    }
    return res
};
/* 统计 */
var maxNumberOfBalloons = function (text) {
    const cnt = new Array(5).fill(0)
    for (const ch of text) {
        switch (ch) {
            case "b":
                cnt[0]++
                break
            case "a":
                cnt[1]++
                break
            case "l":
                cnt[2]++
                break
            case "o":
                cnt[3]++
                break
            case "n":
                cnt[4]++
                break
        }

    }
    cnt[2] = Math.floor(cnt[2] / 2)
    cnt[3] = Math.floor(cnt[3] / 2)

    return Math.min(...cnt)
}
maxNumberOfBalloons("balloon")